package com.ruoyi.agriculture.zs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.agriculture.zs.service.IZsQuestionLikeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.agriculture.zs.domain.ZsQuestion;
import com.ruoyi.agriculture.zs.service.IZsQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问答Controller
 *
 * @author zs
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/zs/question")
public class ZsQuestionController extends BaseController
{
    @Autowired
    private IZsQuestionService zsQuestionService;

    @Autowired
    private IZsQuestionLikeService zsQuestionLikeService;

    /**
     * 查询问答列表
     */
    @PreAuthorize("@ss.hasPermi('zs:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZsQuestion zsQuestion)
    {
        startPage();
        List<ZsQuestion> list = zsQuestionService.selectZsQuestionList(zsQuestion);
        for (ZsQuestion item : list) {
        }
        return getDataTable(list);
    }

    /**
     * 导出问答列表
     */
    @PreAuthorize("@ss.hasPermi('zs:question:export')")
    @Log(title = "问答", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZsQuestion zsQuestion)
    {
        List<ZsQuestion> list = zsQuestionService.selectZsQuestionList(zsQuestion);
        ExcelUtil<ZsQuestion> util = new ExcelUtil<ZsQuestion>(ZsQuestion.class);
        util.exportExcel(response, list, "问答数据");
    }

    /**
     * 获取问答详细信息
     */
    @PreAuthorize("@ss.hasPermi('zs:question:query')")
    @GetMapping(value = "/{zsQuestionId}")
    public AjaxResult getInfo(@PathVariable("zsQuestionId") Long zsQuestionId)
    {
        return success(zsQuestionService.selectZsQuestionByZsQuestionId(zsQuestionId));
    }

    /**
     * 新增问答
     */
    @PreAuthorize("@ss.hasPermi('zs:question:add')")
    @Log(title = "问答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsQuestion zsQuestion)
    {
        return toAjax(zsQuestionService.insertZsQuestion(zsQuestion));
    }

    /**
     * 修改问答
     */
    @PreAuthorize("@ss.hasPermi('zs:question:edit')")
    @Log(title = "问答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsQuestion zsQuestion)
    {
        return toAjax(zsQuestionService.updateZsQuestion(zsQuestion));
    }

    /**
     * 删除问答
     */
    @PreAuthorize("@ss.hasPermi('zs:question:remove')")
    @Log(title = "问答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zsQuestionIds}")
    public AjaxResult remove(@PathVariable Long[] zsQuestionIds)
    {
        return toAjax(zsQuestionService.deleteZsQuestionByZsQuestionIds(zsQuestionIds));
    }
}
